﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="RoleManager.aspx.cs" Inherits="RoleBasedSecurity.RoleManager" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     <style type="text/css">
        #mainDiv div
        {
            border: 1px solid #666;
            margin: 10px;
        }

        .rCode
        {
            font-variant: small-caps;
        }
    </style>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
     <script type="text/javascript">
         function checkSelected() {             
             $("#<%= btnMove.ClientID%>").attr("disabled", "true");
             $("#<%= btnRemove.ClientID%>").attr("disabled", "true");

             if ('<%= User.IsInRole("ADMIN")%>' == 'True') {
                 if ($("#<%= assignedRoles.ClientID%> option:selected").length != 0) {
                     $("#<%= btnMove.ClientID%>").removeAttr("disabled");
                 }
                 if ($("#<%= unAssignedRoles.ClientID%> option:selected").length != 0) {
                     $("#<%= btnRemove.ClientID%>").removeAttr("disabled");
                 }
             }
        }
        function check() {
            checkSelected();
            $("#<%= assignedRoles.ClientID%>").change(function () {
                checkSelected();
            });
            $("#<%= unAssignedRoles.ClientID%>").change(function () {
                checkSelected();
            });
        }
        $(document).ready(function () {
            checkSelected();
        });
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {            
            check();
        });
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function () {
            check();
        });
    </script>
    <div id="mainDiv">
        <div id="adminDiv">
            <div>Available Roles:<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox></div>
            <div>
                <b>Add Roles:</b>
                Role Code:
                <asp:TextBox ID="txtRolecode" runat="server" CssClass="rCode"></asp:TextBox>
                Role Name:
                <asp:TextBox ID="txtRolename" runat="server"></asp:TextBox>
                Description:
                <asp:TextBox ID="txtroleDesc" runat="server" TextMode="MultiLine"></asp:TextBox>
                <asp:Button ID="btnAddRole" runat="server" Text="Add Role" OnClick="btnAddRole_Click" />
            </div>
        </div>
        <div style="vertical-align: top;"> 
            <div style="width:300px; display:inline-block;vertical-align: top;"><span style="vertical-align:top;">Users: </span>
                <asp:ListBox ID="listUsers" runat="server" AutoPostBack="true"
                    onselectedindexchanged="listUsers_SelectedIndexChanged" Height="93px" 
                    Width="183px"></asp:ListBox></div>
            <div style="width:300px; display:inline-block;vertical-align: top;"><span style="vertical-align:top;">Assigned Roles:</span><asp:ListBox 
                    ID="assignedRoles" runat="server"  SelectionMode="Multiple"
                onselectedindexchanged="assignedRoles_SelectedIndexChanged" Height="93px"
                    Width="188px"></asp:ListBox></div>
            <div id="btns" style="width:100px; border:none; display:inline-block;vertical-align: top;">                
                <asp:Button ID="btnRemove" runat="server" Text="Assign" Width="70"
                    onclick="btnRemove_Click" />      
                <asp:Button ID="btnMove" runat="server" Text="Remove" Width="70" 
                    onclick="btnMove_Click" />     
                </div>
            <div  style="width:300px; display:inline-block;vertical-align: top;"><span style="vertical-align:top;">Unassigned Roles:</span><asp:ListBox  SelectionMode="Multiple"
                    ID="unAssignedRoles" runat="server" Height="92px" Width="175px"></asp:ListBox></div>
            
        </div>
    </div>
</asp:Content>
